﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WanPiJie.WebSite.MyBaby
{
	public partial class GrowthRecordIndex : PageMustLogin_Baby
	{
		public IList<GrowthRecord> GrowthRecords { get; set; }

		public string HeightJS { get; set; }

		public string WeightJS { get; set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			GrowthRecords = WpjSf.GrowthRecordService.GetGrowthRecords(this.Baby.Id);
			this.Repeater1.DataSource = GrowthRecords.OrderByDescending(p => p.SurveyDate).ToList();
			this.Repeater1.DataBind();

			if (this.GrowthRecords.Count > 0)
			{
				this.HeightJS = GrowthRecords.Aggregate(
					"[",
					(a, item) =>
					{
						string p = "[" + item.Height + "," + this.Baby.GetIntervalAfterBirth(item.SurveyDate).Days + "]";
						return a == "[" ? a + p : a + "," + p;
					},
					a => { return a + "]"; });

				this.WeightJS = GrowthRecords.Aggregate(
					"[",
					(a, item) =>
					{
						string p = "[" + item.Weight + "," + this.Baby.GetIntervalAfterBirth(item.SurveyDate).Days + "]";
						return a == "[" ? a + p : a + "," + p;
					},
					a => { return a + "]"; });
			}
			else
			{
				this.HeightJS = "[]";
				this.WeightJS = "[]";
			}
		}
	}
}